

<template>
  <div>
    <basic-container>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>版本推广管理</el-breadcrumb-item>
        <el-breadcrumb-item>Android版本管理</el-breadcrumb-item>
      </el-breadcrumb>
    </basic-container>
    <basic-container>
      <avue-crud
        ref="crud"
        :data="data"
        v-model="form"
        :option="option"
        :page.sync="page"
        @on-load="getList"
        @refresh-change="refreshChange"
        @search-reset="from = {}"
        @search-change="searchChange"
        @row-update="rowUpdate"
        @row-save="rowSave"
        :upload-after="uploadAfter"
      >
        <!-- 自定义按钮 -->
        <template slot="realese_url" slot-scope="scope">
          <el-row>
            <a :href="scope.row.realese_url">
              <el-button type="primary" size="mini">下载</el-button>
            </a>
          </el-row>
        </template>
        <template
          slot="last_update_info"
          slot-scope="scope"
          style="width: 180px"
        >
          {{ scope.row.last_update_info }}
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import { catUrl } from "@/config/env";
import { common } from "@/api/cat/httpRequest";
import { versionManager as baseUrl, uploadFile } from "@/api/cat/baseUrls";
export default {
  data() {
    return {
      page: {
        total: 0,
        pageSize: 10,
      },
      type: true,
      data: [],
      params: {},
      form: {},
      option: {
        tip: true,
        align: "center",
        border: true,
        delBtn: false,
        editBtn: true,
        searchBtn: true,
        addBtn: true,
        headerAlign: "center",
        expand: false,
        column: [
          {
            label: "渠道id",
            prop: "channel_id",
            type: "input",
            search: true,
            required: true,
            rules: [
              {
                required: true,
                message: "渠道id必须填写",
              },
            ],
          },
          {
            label: "版本号",
            prop: "versions",
            type: "input",
            search: true,
            required: true,
            rules: [
              {
                required: true,
                message: "版本号必须填写",
              },
            ],
          },
          {
            label: "版本数字标识",
            prop: "version_number",
            span: 24,
            type: "input",
            search: true,
            required: true,
            rules: [
              {
                required: true,
                message: "版本数字标识必须填写",
              },
            ],
          },
          {
            label: "下载包",
            prop: "realese_url",
            type: "input",
            slot: true,
            span: 18,
            required: true,
            rules: [
              {
                required: true,
                message: "下载包路径必须填写",
              },
            ],
          },
          {
            label: "",
            prop: "real_path_url",
            type: "upload",
            align: "left",
            span: 6,
            hide: true,
            action: `${catUrl}${uploadFile.uploadFile}`,
          },

          {
            label: "备注信息",
            prop: "notes",
            type: "textarea",
            required: true,
            rules: [
              {
                required: true,
                message: "备注信息必须填写",
              },
            ],
          },
          {
            label: "启停状态",
            prop: "using_state",
            type: "select",
            search: true,
            required: true,
            dicData: [
              {
                label: "未启用",
                value: 0,
              },
              {
                label: "正使用",
                value: 1,
              },

              {
                label: "已停用",
                value: 2,
              },
            ],
            props: {
              label: "label",
              value: "value",
            },
            rules: [
              {
                required: true,
                message: "启停状态必须填写",
              },
            ],
          },
          {
            label: "最后操作信息",
            prop: "last_update_info",
            type: "input",
            addDisplay: false,
            editDisplay: false,
            addDisabled: true,
            editDisabled: true,
            readonly: true,
            required: true,
            slot: true,
          },
          {
            label: "是否强制升级",
            prop: "is_force_upgrade",
            type: "select",
            required: true,
            rules: [
              {
                required: true,
                message: "是否强制升级必须填写",
              },
            ],
            dicData: [
              {
                label: "否",
                value: 0,
              },
              {
                label: "是",
                value: 1,
              },
            ],
            props: {
              label: "label",
              value: "value",
            },
          },
        ],
      },
    };
  },
  methods: {
    /**获取列表 */
    async getList() {
      this.loading = true;
      //清空表格列表
      this.data = [];
      this.params.orderByList = "version_number&DESC";
      //发送请求获取数据
      let response = await common(
        `${baseUrl.pageAndParam}`,
        { ...this.params, ...this.defalut },
        this.page,
        "POST"
      );

      this.page = response.page;
      this.data = response.data;
      this.loading = false;
    },
    /**刷新 */
    refreshChange() {
      this.getList();
    },
    /**搜索 */
    searchChange(params, done) {
      params.reply_content = `${
        params.reply_content ? "%" + params.reply_content + "%" : ""
      }`;
      params.content = `${params.content ? "%" + params.content + "%" : ""}`;
      params.create_time = `${
        params.create_time ? "!<>!" + params.create_time : ""
      }`;
      params.state = params.states;
      delete params.states;
      this.params = params;
      this.page.currentPage = 1;
      this.getList();
      if (done) done();
    },
    /**保存 */
    async rowSave(row, done) {
      delete this.form["id"];
      let userInfo = this.$store.state.user.userInfo;
      this.form.last_update_info = `<${userInfo.id ? userInfo.id + " " : ""}${
        userInfo.username
      }>`;
      this.form.app_id = 61096114;
      let data = await common(baseUrl.save, this.form, null, "POST");
      if (data == null) {
        return;
      }
      this.getList();
      done();
    },
    /**修改 */
    async rowUpdate(row, index, done, loading) {
      let userInfo = this.$store.state.user.userInfo;
      row.last_update_info = `<${userInfo.id ? userInfo.id + " " : ""}${
        userInfo.username
      }>`;
      row.app_id = 61096114;
      let data = await common(baseUrl.update, row, null, "POST");
      if (data == null) {
        loading();
        return;
      }
      this.getList();
      done();
    },
    /** 文件上传成功后的方法 */
    uploadAfter(res, done, loading, column) {
      this.form.realese_url = res.source;
      done();
    },
  },
};
</script>
<style>
.el-upload-list--text {
  display: none !important;
}
</style>